//GKL appendix replication

cd "/Users/spencergoidel/Dropbox/PartyPie/Data"

use "POQ_GKL_2021_SI.dta", clear

tsset date 
drop rep_a1 dem_a1

order date rep dem nonpartisan ind_a1 dkna_a1 rep_a2 dem_a2 ind_a2 macrop dem_pres dem_approve dem_csi dapprove dcsi approve csi 

//Figure A1: shocks in approval (left) and consumer sentiment (right) w/ dkna as separate category
//left side
dynsimpie dem_csi dem_pres, dvs(ind_a1 dkna_a1 rep dem) ar(1 2) shockvars(dem_approve) shockvals(6.379107)
effectsplot

//right side
dynsimpie dem_approve dem_pres, dvs(ind_a1 dkna_a1 rep dem) ar(1) shockvars(dem_csi) shockvals(4.998399)
effectsplot


//Figure A2: shocks in approval (left) and consumer sentiment (right) w/ dkna omitted
//left side
dynsimpie dem_csi dem_pres, dvs(ind_a2 rep_a2 dem_a2) ar(1) shockvars(dem_approve) shockvals(6.379107)
effectsplot

//right side
dynsimpie dem_approve dem_pres, dvs(ind_a2 rep_a2 dem_a2) ar(1) shockvars(dem_csi) shockvals(4.998399)
effectsplot


//Table A3: unit root tests
dfuller dem
pperron dem
dfuller rep
pperron rep
dfuller nonpartisan
pperron nonpartisan
dfuller approve
pperron approve
dfuller csi
pperron csi
dfuller dapprove
pperron dapprove
dfuller dcsi 
pperron dcsi 


//Table A4: traditional macropartisanship
reg macrop l.macrop l2.macrop dem_approve dem_csi dem_pres
est sto macrop
esttab macrop, se t(%9.4f) nogap replace

//calculate cumulative effect of standard deviation shock in approval 
di _b[dem_approve]*6.379107
di _b[dem_approve]/(1-(_b[l.macrop]+_b[l2.macrop]))
di .00818173*6.379107


//Table A5: compositional macropartisanship
dynsimpie dem_csi dem_pres, dvs(nonpartisan rep dem) ar(1 2) shockvars(dem_approve) shockvals(6.379107)
est sto compositional
esttab compositional, se t(%9.4f) nogap replace


//Table A6: purged approval
//purge approval of consumer sentiment 
reg approve l.approve dcsi
predict res_approve_a6, residuals

//transform so the IVs move in a Democratic direction
gen dem_approve_a6 = res_approve_a6 if dem_pres > 0
replace dem_approve_a6 = res_approve_a6*-1 if dem_pres < 1

//compositional model w/ purged approval
dynsimpie dem_csi dem_pres, dvs(nonpartisan rep dem) ar(1 2) shockvars(dem_approve_a6) shockvals(5.95098)
est sto dyn_approve_a6
esttab dyn_approve_a6, se b(%9.4f) t(%9.4f) nogap replace


//Table A7: purged approval w/ dummies
//purge approval of consumer sentiment and dummies
reg approve l.approve dcsi sep_11 ron1 hw1 bill1 w1 obama1 achille_lauro-ass_attempt
predict res_approve_a7, residuals

//transform so the IVs move in a Democratic direction
gen dem_approve_a7 = res_approve_a7 if dem_pres > 0
replace dem_approve_a7 = res_approve_a7*-1 if dem_pres < 1

//compositional model w/ purged approval
dynsimpie dem_csi dem_pres, dvs(nonpartisan rep dem) ar(1 2) shockvars(dem_approve_a7) shockvals(5.95098)
est sto dyn_approve_a7
esttab dyn_approve_a7, se b(%9.4f) t(%9.4f) nogap replace


//Table A8: compositional model w/ dummies
dynsimpie dem_csi dem_pres sep_11 ron1 hw1 bill1 w1 obama1 achille_lauro-ass_attempt, dvs(nonpartisan rep dem) ar(1 2) shockvars(dem_approve) shockvals(5.95098)
est sto dyn_approve_a8
esttab dyn_approve_a8, se wide b(%9.4f) t(%9.4f) nogap replace


//Table A9: without approval
dynsimpie dem_pres, dvs(nonpartisan rep dem) ar(1 2) shockvars(dem_csi) shockvals(4.998399)
est sto dyn_csi_a9
esttab dyn_csi_a9, se b(%9.4f) t(%9.4f) nogap replace


//Footnote 4: test for autocorrelation
tlogit rep rep_nonpartisan dem dem_nonpartisan, base(nonpartisan)

sureg (rep_nonpartisan l.rep_nonpartisan l2.rep_nonpartisan dem_approve dem_csi dem_pres) (dem_nonpartisan l.dem_nonpartisan l2.dem_nonpartisan dem_approve dem_csi dem_pres)

//Portmanteau (q) test
predict residuals2lag, residuals
wntestq residuals2lag

//Breusch-godfrey test
reg residuals2lag
bgodfrey

//Harvey test
sureg (rep_nonpartisan l.rep_nonpartisan l2.rep_nonpartisan dem_approve dem_csi dem_pres) (dem_nonpartisan l.dem_nonpartisan l2.dem_nonpartisan dem_approve dem_csi dem_pres)
lmareg3


